package com.hs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.entity.dto.Comment;
import com.hs.entity.dto.TeamEmp;
import com.hs.mapper.CommentMapper;
import com.hs.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {


    @Resource
    private CommentMapper commentMapper;
    @Override
    public PageInfo<Comment> selectCommentList(Integer currentNum, String keywords) {
        PageHelper.startPage(currentNum,3);

        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();

        if (keywords != null && !keywords.isEmpty()) {
            queryWrapper.like("team_name", keywords);
        }
//        queryWrapper.orderByDesc("create_time");
        List<Comment> commentList = commentMapper.selectListWithTeamAndUser(queryWrapper);

        return new PageInfo<>(commentList);
    }

    @Override
    public PageInfo<Comment> selectCommentListByTeamId(Integer currentNum, Integer teamId) {
        // 设置分页
        PageHelper.startPage(currentNum, 4);

        // 构建查询条件
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", teamId);

        // 调用mapper查询
        List<Comment> commentList = commentMapper.selectListWithTeamAndUser(queryWrapper);

        // 返回分页信息
        return new PageInfo<>(commentList);
    }

    @Override
    public List<Comment> selectLikeById(Integer id) {
     QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", id);
        return commentMapper.selectListWithTeamAndUser(queryWrapper);
    }

    @Override
    public void likeComment(Integer id) {
        commentMapper.incrementLikeCount(id);
    }

    @Override
    public List<Comment> selectAllCommentListByTeamId(Integer id) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("team_id", id);
        return commentMapper.selectListWithTeamAndUser(queryWrapper);
    }
}
